package com.nbsaas.boot.product.data.entity;


import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.jpa.data.entity.AbstractEntity;
import com.nbsaas.boot.jpa.data.entity.User;
import com.nbsaas.boot.rest.enums.StoreState;
import com.nbsaas.boot.rest.filter.Operator;
import com.nbsaas.boot.shop.data.entity.Shop;
import lombok.Data;
import org.hibernate.annotations.Comment;

import javax.persistence.*;


@BeanExt(
        items = {
                @FormExtField(fieldName = "productLogo", parentField = "logo", parent = "product", fieldClass = String.class)
        }
)
@org.hibernate.annotations.Table(appliesTo = "bs_product_visit", comment = "商品浏览记录")
@Data
@FormAnnotation( model = "商品浏览记录")
@Entity
@Table(name = "bs_product_visit")
public class ProductVisit extends AbstractEntity {

    @SearchItem(label = "商家", name = "shop", key = "shop.id", operator = Operator.eq, classType = Long.class, show = false)
    @Comment("商家id")
    @JoinColumn(name = "shop_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    @FieldConvert
    @FieldName
    @ManyToOne(fetch = FetchType.LAZY)
    private Shop shop;


    @SearchItem(label = "商品", name = "product", key = "product.id", operator = Operator.eq, classType = Long.class, show = false)
    @JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    @FieldConvert
    @FieldName
    @ManyToOne(fetch = FetchType.LAZY)
    private Product product;

    @SearchItem(label = "用户", name = "creator", key = "creator.id", operator = Operator.eq, classType = Long.class, show = false)
    @JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private User creator;

}
